<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>抽奖页面</title>
    <!-- <script type="text/javascript" src="./HTML/js/choujiang.js"></script> -->
    <!-- <script type="text/javascript" src="/HTML/js/script.js"></script> -->
</head>
<body>
    <h1>简易抽奖器</h1>
    <div id="lottery">点击开始抽奖</div>
    <button id="start" onclick="start()">开始</button>
    <button id="stop" onclick="stop()">停止</button>
</body>
<script>
    var names = ["张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十"];
var isRunning = false;
var intervalId;

function start() {
    // 开始运行，给 isRunning 赋值为 true
    isRunning = true;
    // 使用 setInterval 实现延迟效果
    intervalId = setInterval(function() {
        // 随机获取一个索引值
        var index = Math.floor(Math.random() * names.length);
        // 获取到索引值，获取到对应的名字
        var name = names[index];
        // 把名字显示到 lottery 中
        document.getElementById("lottery").innerHTML = name;
    }, 100); // 每 100 毫秒更新一次
}

function stop() {
    // 停止运行，给 isRunning 赋值为 false
    isRunning = false;
    // 使用 clearInterval 停止 setInterval
    clearInterval(intervalId);
}
</script>
</html>